//
//  GUFunctions.m
//  functions
//
//  Created by world on 13-6-9.
//  Copyright (c) 2013年 world. All rights reserved.
//

#import "GUFunctions.h"

inline NSString *NSStringFromBOOL(BOOL value){
    if (value) {
        return @"YES";
    }else{
        return @"NO";
    }
}

inline BOOL  NSStringToBOOL(NSString* value){
    if (value == nil) {
        return NO;
    }
    if ([@"YES" isEqualToString:[value uppercaseString]]) {
        return YES;
    }
    return NO;
}


inline  UIImage* imageByName(NSString* name){
    return [UIImage imageNamed:name];
}


inline  UIImage* imageByURL(NSString* urlStr){
    NSURL* url = [NSURL URLWithString:urlStr];
    if (url == nil) {
        return nil;
    }
    NSData* imageData = [NSData dataWithContentsOfURL:url];
    if(imageData == nil){
       return nil;
    }
    return [UIImage imageWithData:imageData];
}


inline  UIImage* imageToSize(UIImage* image, CGSize targetSize){
    UIGraphicsBeginImageContextWithOptions(targetSize, NO, 0);
    [image drawInRect:CGRectMake(0, 0, targetSize.width, targetSize.height)];
    UIImage *targetImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return targetImage;
}



inline BOOL isNSStringEmpty(NSString* value){
    if (value == nil || [value length] == 0) {
        return YES;
    }
    return NO;
}



inline BOOL isNSStringBlank(NSString* value){
    if (value == nil || [value length] == 0) {
        return YES;
    }
    
    if ([[value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0) {
        return YES;
    };
    return NO;
}





